package cn.yeyiu.netonlinevideo.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.alibaba.fastjson.JSONObject;

import cn.yeyiu.netonlinevideo.R;
import cn.yeyiu.netonlinevideo.adapter.OnlineSourceAdapter;
import cn.yeyiu.netonlinevideo.bean.SourceData;
import cn.yeyiu.netonlinevideo.util.ParserFactory;
import cn.yeyiu.netonlinevideo.util.SourceUtil;
import cn.yeyiu.netonlinevideo.viewmodel.DataListViewModel;

/**
 * 网络源选择 主界面
 * <p>
 * 传递源获取器至
 * 1.simpletabdatalist
 * 2.tabdatalist
 * 3.multitabdatalist
 */

public class OnlineMainActivity extends AppCompatActivity {

    private RecyclerView rv;

    private View backLL;
    private View localLL;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_net_online);

        initSources();
        viewInit();
        adapterInit();
        eventInit();
        test();
    }


    void initSources() {
        SourceUtil.initViewModel(new ViewModelProvider(this).get(DataListViewModel.class));
        ParserFactory.initSources(SourceUtil.getSourceList(this));
    }

    void viewInit() {
        rv = findViewById(R.id.net_src_rv);
        backLL = findViewById(R.id.back_ll);
        localLL = findViewById(R.id.local_video_ll);
    }

    void adapterInit() {
        OnlineSourceAdapter adapter = new OnlineSourceAdapter(this);
        rv.setAdapter(adapter);
        rv.setLayoutManager(new GridLayoutManager(this, 3));
    }

    void eventInit() {
        backLL.setOnClickListener(v -> {
            finish();
        });
        localLL.setOnClickListener(v -> {
            Intent i = new Intent(this, SingleTabDataListActivity.class);
            SourceData source = new SourceData();
            source.code = "local";
            source.name = "本地局域网";
            i.putExtra("src", JSONObject.toJSONString(source));
            startActivity(i);
        });
    }

    void test() {
    }
}